package config;

import com.newsproject.MyInterceptor.LogInterceptor;
import com.newsproject.MyInterceptor.LoginInterceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LogInterceptor())
                .addPathPatterns("/user/**","/NewsController/**","/creator/**","/category/**");
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/user/personal_page","/creator","/NewsController/**")
                .excludePathPatterns(
                        "/NewsController/{postId}",
                        "/NewsController/toPost",
                        "NewsController/comment",
                        "/NewsController/selectComment/{postId}");
         registry.addInterceptor(new LoginInterceptor())
               .addPathPatterns("/GetAnnouncementController/**"); // 拦截GetAnnouncementController接口，登录后才能访问
    }

}
